﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialIn.Biz;
using System.Data;
//using AjaxControlToolkit;

namespace SocialIn.Web.MyPage
{
    public partial class VoluntaryActivityRequest : System.Web.UI.Page
    {
        #region 프로퍼티
        private string level = "2";
        private string mapX = "";
        private string mapY = "";
        private string width = "400";
        private string height = "400";
        private string pan = "10";
        private string tilt = "-30";

        public string Level
        {
            get
            {
                return level;
            }
            set
            {
                level = value;
            }
        }
        public string MapKey { get; set; }
        public string Width
        {
            get
            {
                return width;
            }
            set
            {
                width = value;
            }
        }
        public string Height
        {
            get
            {
                return height;
            }
            set
            {
                height = value;
            }
        }
        public string MapX
        {
            get
            {
                return mapX;
            }
            set
            {
                mapX = value;
            }
        }
        public string MapY
        {
            get
            {
                return mapY;
            }
            set
            {
                mapY = value;
            }
        }

        public string Position
        {
            get
            {
                if (string.IsNullOrEmpty(mapX) || string.IsNullOrEmpty(mapY))
                    return "37.529196714213114, 126.92506196011036";
                else
                    return mapX + "," + mapY;
            }
        }
        public string Pan
        {
            get
            {
                return pan;
            }
            set
            {
                pan = value;
            }
        }
        public string Tilt
        {
            get
            {
                return tilt;
            }
            set
            {
                tilt = value;
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                InitSetting();
            }
        }

        private void InitSetting()
        {
            CommonData common = new CommonData();
            DataTable result = common.GetCodeMaster("M003").ReturnValue;

            foreach (DataRow row in result.Rows)
            {
                string imgPath = String.Format("<br/><img alt='[{0}]{1}' title='[{0}]{1}' src='{2}' />"
                                , row["CodeName"], row["Etc2"]
                                , VirtualPathUtility.ToAbsolute(row["Etc1"].ToString()));

                this.rblTalent.Items.Add(new ListItem(imgPath, row["SubCategory"].ToString()));
            }

            this.rblTalent.DataBind();

            for (int i = 0; i < 24; i++)
            {
                this.ddlHour.Items.Add(new ListItem(i.ToString("00")));
            }

            for (int i = 0; i < 6; i++)
            {
                int mi = i * 10;

                this.ddlMinute.Items.Add(new ListItem(mi.ToString("00")));
            }

            for (int i = 1; i < 9; i++)
            {
                this.ddlTimespan.Items.Add(new ListItem(i.ToString()));
            }
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string talentID = this.rblTalent.SelectedValue;
            string date = this.tbDate.Text;
            string hour = this.ddlHour.SelectedValue;
            string minute = this.ddlMinute.SelectedValue;
            string span = this.ddlTimespan.SelectedValue;

            DateTime tempDate = Convert.ToDateTime(date);
            tempDate = tempDate.AddHours(Convert.ToInt32(hour));
            tempDate = tempDate.AddMinutes(Convert.ToInt32(minute));

            DateTime tempDate2 = tempDate.AddHours(Convert.ToInt32(span));            

            VoluntaryActivity volun = new VoluntaryActivity();
            bool completed = volun.RegisterHelpRequest(Page.User.Identity.Name, this.tbEvent.Text
                , talentID
                , this.tbEvent.Text, tempDate, tempDate2, this.tbLocation.Text, "", "", "", "", "", 1, Convert.ToInt32(this.tbComplement.Text));

            if (completed)
            {
                Response.Redirect("~/GiveAndTake/TakeInformation.aspx");
            }
        }
    }
}